#include "KeyStateModel.h"
#include "Common/Information.h"
#include "ssas_api.h"
#define LOG_TAG "HMI"
#include "log_api.h"

static VehicleKeyState keyState;

static void run()
{
    int msgState = COM_MSG_INIT;
    Std_ReturnType comRet = E_NOT_OK;

    do
    {
        msgState = get_message_state(COM_IC_HEV_GENERAL_STATUS_1);
        if(COM_MSG_TIMEOUT == msgState || COM_MSG_INIT == msgState/*todo maybe remove*/)
        {
            keyState = VEHILE_OFF;
            break;
        }

        int rawData = 0;
        comRet = Com_ReceiveSignal(COM_SID_VCUKyPstn, &rawData);
        if(E_NOT_OK == comRet)
        {
            keyState = VEHILE_OFF;
            break;
        }

        switch (rawData)
        {
            case 0:
                keyState = VEHILE_OFF;
                break;

            case 1:
                keyState = VEHILE_ACC;
                break;

            case 2:
                keyState = VEHILE_ON;
                break;

            case 3:
                keyState = VEHILE_START;
                break;
            
            default:
                keyState = VEHILE_OFF;
                break;
        }
        break;
    } while (false); 
}

VehicleKeyState getVehileState()
{
    return keyState;
}

static void init()
{
    keyState = VEHILE_OFF;
}

static void release()
{

}

KeyStateModel g_KeyStateModelInstance = {
    // ImeterModel
    {
        init,
        run,
        release,
        MIN_PERIOD,
    },
};
